Public Sub BarcodeReader_ReadBarcodeExample4()
Dim imageFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Barcode1.tif")
' Create a Barcode engine
Dim engine As New BarcodeEngine()
' Get the Barcode reader instance
Dim reader As BarcodeReader = engine.Reader
Using codecs As New RasterCodecs()
Using image As RasterImage = codecs.Load(imageFileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1)
' Rotate the image by 90, so default option of reading horizonal barcodes will not work
Console.WriteLine("Rotating the image by 90 degrees")
Dim rotate As New RotateCommand(90 * 100, RotateCommandFlags.Resize, RasterColor.FromKnownColor(RasterKnownColor.White))
rotate.Run(image)
' In the US, UPC barcodes are used to identity products. So, create an array of UPC symbologies
Dim upcSymbologies() As BarcodeSymbology = _
{ _
BarcodeSymbology.UPCA, _
BarcodeSymbology.UPCE _
}
' Read the first UPC barcode from the image using default options
Console.WriteLine("Reading barcodes using default options")
Dim barcode As BarcodeData = reader.ReadBarcode(image, LogicalRectangle.Empty, upcSymbologies, Nothing)
' Show its location and data if found
' This will print out "Not found"
If Not IsNothing(barcode) Then
Console.WriteLine("Found a {0} barcode at {1}, data:\n{2}", barcode.Symbology, barcode.Bounds, barcode.Value)
Else
Console.WriteLine("Not found")
End If
' Now get the options we used previously, and change the 1D linear barcode read options
' to search for barcodes in both horizontal and vertical directions
' Note: Same options are used for UPCA and UPCE, so we only need one options class
Dim oneDReadOptions As OneDBarcodeReadOptions = DirectCast(reader.GetDefaultOptions(BarcodeSymbology.UPCA), OneDBarcodeReadOptions)
' Change the read direction
oneDReadOptions.SearchDirection = BarcodeSearchDirection.HorizontalAndVertical
' Try again using our options
Console.WriteLine("Reading barcodes using our options")
barcode = reader.ReadBarcode(image, LogicalRectangle.Empty, upcSymbologies, New BarcodeReadOptions() {oneDReadOptions})
' Show its location and data if found
' This will find the barcode and print its information now
If Not IsNothing(barcode) Then
Console.WriteLine("Found a {0} barcode at {1}, data:\n{2}", barcode.Symbology, barcode.Bounds, barcode.Value)
Else
Console.WriteLine("Not found")
End If
End Using
End Using
End Sub
Public NotInheritable Class LEAD_VARS
Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class
public void BarcodeReader_ReadBarcodeExample4()
{
string imageFileName = Path.Combine(LEAD_VARS.ImagesDir, "Barcode1.tif");
// Create a Barcode engine
BarcodeEngine engine = new BarcodeEngine();
// Get the Barcode reader instance
BarcodeReader reader = engine.Reader;
using(RasterCodecs codecs = new RasterCodecs())
{
using(RasterImage image = codecs.Load(imageFileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1))
{
// Rotate the image by 90, so default option of reading horizonal barcodes will not work
Console.WriteLine("Rotating the image by 90 degrees");
RotateCommand rotate = new RotateCommand(90 * 100, RotateCommandFlags.Resize, RasterColor.FromKnownColor(RasterKnownColor.White));
rotate.Run(image);
// In the US, UPC barcodes are used to identity products. So, create an array of UPC symbologies
BarcodeSymbology[] upcSymbologies =
{
BarcodeSymbology.UPCA,
BarcodeSymbology.UPCE
};
// Read the first UPC barcode from the image using default options
Console.WriteLine("Reading barcodes using default options");
BarcodeData barcode = reader.ReadBarcode(image, LogicalRectangle.Empty, upcSymbologies, null);
// Show its location and data if found
// This will print out "Not found"
if(barcode != null)
{
Console.WriteLine("Found a {0} barcode at {1}, data:\n{2}", barcode.Symbology, barcode.Bounds, barcode.Value);
}
else
{
Console.WriteLine("Not found");
}
// Now get the options we used previously, and change the 1D linear barcode read options
// to search for barcodes in both horizontal and vertical directions
// Note: Same options are used for UPCA and UPCE, so we only need one options class
OneDBarcodeReadOptions oneDReadOptions = reader.GetDefaultOptions(BarcodeSymbology.UPCA) as OneDBarcodeReadOptions;
// Change the read direction
oneDReadOptions.SearchDirection = BarcodeSearchDirection.HorizontalAndVertical;
// Try again using our options
Console.WriteLine("Reading barcodes using our options");
barcode = reader.ReadBarcode(image, LogicalRectangle.Empty, upcSymbologies, new BarcodeReadOptions[] { oneDReadOptions });
// Show its location and data if found
// This will find the barcode and print its information now
if(barcode != null)
{
Console.WriteLine("Found a {0} barcode at {1}, data:\n{2}", barcode.Symbology, barcode.Bounds, barcode.Value);
}
else
{
Console.WriteLine("Not found");
}
}
}
}
static class LEAD_VARS
{
public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
}
public void BarcodeReader_ReadBarcodeExample4(RasterImage image)
{
// Create a Barcode engine
BarcodeEngine engine = new BarcodeEngine();
// Get the Barcode reader instance
BarcodeReader reader = engine.Reader;
RasterCodecs codecs = new RasterCodecs();
// Rotate the image by 90, so default option of reading horizonal barcodes will not work
Console.WriteLine("Rotating the image by 90 degrees");
RotateCommand rotate = new RotateCommand(90 * 100, RotateCommandFlags.Resize, RasterColor.FromKnownColor(RasterKnownColor.White));
rotate.Run(image);
// In the US, UPC barcodes are used to identity products. So, create an array of UPC symbologies
BarcodeSymbology[] upcSymbologies =
{
BarcodeSymbology.UPCA,
BarcodeSymbology.UPCE
};
// Read the first UPC barcode from the image using default options
Console.WriteLine("Reading barcodes using default options");
BarcodeData barcode = reader.ReadBarcode(image, LogicalRectangle.Empty, upcSymbologies, null);
// Show its location and data if found
// This will print out "Not found"
if(barcode != null)
{
Console.WriteLine("Found a {0} barcode at {1}, data:\n{2}", barcode.Symbology, barcode.Bounds, barcode.Value);
}
else
{
Console.WriteLine("Not found");
}
// Now get the options we used previously, and change the 1D linear barcode read options
// to search for barcodes in both horizontal and vertical directions
// Note: Same options are used for UPCA and UPCE, so we only need one options class
OneDBarcodeReadOptions oneDReadOptions = reader.GetDefaultOptions(BarcodeSymbology.UPCA) as OneDBarcodeReadOptions;
// Change the read direction
oneDReadOptions.SearchDirection = BarcodeSearchDirection.HorizontalAndVertical;
// Try again using our options
Console.WriteLine("Reading barcodes using our options");
barcode = reader.ReadBarcode(image, LogicalRectangle.Empty, upcSymbologies, new BarcodeReadOptions[] { oneDReadOptions });
// Show its location and data if found
// This will find the barcode and print its information now
if(barcode != null)
{
Console.WriteLine("Found a {0} barcode at {1}, data:\n{2}", barcode.Symbology, barcode.Bounds, barcode.Value);
}
else
{
Console.WriteLine("Not found");
}
}
Public Sub BarcodeReader_ReadBarcodeExample4(ByVal image As RasterImage)
' Create a Barcode engine
Dim engine As BarcodeEngine = New BarcodeEngine()
' Get the Barcode reader instance
Dim reader As BarcodeReader = engine.Reader
Dim codecs As RasterCodecs = New RasterCodecs()
' Rotate the image by 90, so default option of reading horizonal barcodes will not work
Console.WriteLine("Rotating the image by 90 degrees")
Dim rotate As RotateCommand = New RotateCommand(90 * 100, RotateCommandFlags.Resize, RasterColor.FromKnownColor(RasterKnownColor.White))
rotate.Run(image)
' In the US, UPC barcodes are used to identity products. So, create an array of UPC symbologies
Dim upcSymbologies As BarcodeSymbology() = {BarcodeSymbology.UPCA, BarcodeSymbology.UPCE}
' Read the first UPC barcode from the image using default options
Console.WriteLine("Reading barcodes using default options")
Dim barcode As BarcodeData = reader.ReadBarcode(image, LogicalRectangle.Empty, upcSymbologies, Nothing)
' Show its location and data if found
' This will print out "Not found"
If Not barcode Is Nothing Then
Console.WriteLine("Found a {0} barcode at {1}, data:" & Constants.vbLf & "{2}", barcode.Symbology, barcode.Bounds, barcode.Value)
Else
Console.WriteLine("Not found")
End If
' Now get the options we used previously, and change the 1D linear barcode read options
' to search for barcodes in both horizontal and vertical directions
' Note: Same options are used for UPCA and UPCE, so we only need one options class
Dim oneDReadOptions As OneDBarcodeReadOptions = TryCast(reader.GetDefaultOptions(BarcodeSymbology.UPCA), OneDBarcodeReadOptions)
' Change the read direction
oneDReadOptions.SearchDirection = BarcodeSearchDirection.HorizontalAndVertical
' Try again using our options
Console.WriteLine("Reading barcodes using our options")
barcode = reader.ReadBarcode(image, LogicalRectangle.Empty, upcSymbologies, New BarcodeReadOptions() {oneDReadOptions})
' Show its location and data if found
' This will find the barcode and print its information now
If Not barcode Is Nothing Then
Console.WriteLine("Found a {0} barcode at {1}, data:" & Constants.vbLf & "{2}", barcode.Symbology, barcode.Bounds, barcode.Value)
Else
Console.WriteLine("Not found")
End If
End Sub